package com.ruoyi.base.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.base.mapper.SysPermissionMapper;
import com.ruoyi.base.domain.SysPermission;
import com.ruoyi.base.service.ISysPermissionService;

/**
 * 系统接口数据Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-03
 */
@Service
public class SysPermissionServiceImpl implements ISysPermissionService 
{
    @Autowired
    private SysPermissionMapper sysPermissionMapper;

    /**
     * 查询系统接口数据
     * 
     * @param id 系统接口数据主键
     * @return 系统接口数据
     */
    @Override
    public SysPermission selectSysPermissionById(String id)
    {
        SysPermission sysPermission = sysPermissionMapper.selectSysPermissionById(id);
        int count = sysPermission.getVisitcount()==null?0:sysPermission.getVisitcount();
        sysPermission.setVisitcount(count+1);
        updateSysPermission(sysPermission);
        return sysPermission;
    }

    /**
     * 查询系统接口数据列表
     * 
     * @param sysPermission 系统接口数据
     * @return 系统接口数据
     */
    @Override
    public List<SysPermission> selectSysPermissionList(SysPermission sysPermission)
    {
        return sysPermissionMapper.selectSysPermissionList(sysPermission);
    }

    /**
     * 新增系统接口数据
     * 
     * @param sysPermission 系统接口数据
     * @return 结果
     */
    @Override
    public int insertSysPermission(SysPermission sysPermission)
    {
        sysPermission.setId(UUID.randomUUID().toString());
        sysPermission.setCreatetime(new Date());
        sysPermission.setCallcount(0);
        sysPermission.setVisitcount(0);
        sysPermission.setApplycount(0);
        sysPermission.setScore(0);
        return sysPermissionMapper.insertSysPermission(sysPermission);
    }

    /**
     * 修改系统接口数据
     * 
     * @param sysPermission 系统接口数据
     * @return 结果
     */
    @Override
    public int updateSysPermission(SysPermission sysPermission)
    {
        sysPermission.setUpdatetime(new Date());
        return sysPermissionMapper.updateSysPermission(sysPermission);
    }

    /**
     * 批量删除系统接口数据
     * 
     * @param ids 需要删除的系统接口数据主键
     * @return 结果
     */
    @Override
    public int deleteSysPermissionByIds(String[] ids)
    {
        return sysPermissionMapper.deleteSysPermissionByIds(ids);
    }

    /**
     * 删除系统接口数据信息
     * 
     * @param id 系统接口数据主键
     * @return 结果
     */
    @Override
    public int deleteSysPermissionById(String id)
    {
        return sysPermissionMapper.deleteSysPermissionById(id);
    }


    @Override
    public int getSysPermissionScore(SysPermission sysPermission) {
        return sysPermission.getApplycount()+sysPermission.getVisitcount()+sysPermission.getCallcount();
    }
}
